package com.geologyoa.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import com.geologyoa.commons.JsonTools;
import com.geologyoa.domain.Cjdw01;
import com.geologyoa.domain.Xmqk01New;
import com.geologyoa.domain.ZHD01;
import com.geologyoa.domain.Zjpf01;
import com.geologyoa.service.SystemManager;
import com.geologyoa.service.SystemManagerImpl;

public class updateXmqk01ForOneToMany extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public updateXmqk01ForOneToMany() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		//[{"ZJPF0101":433,"ZJPF0104":"2013","ZJPF0102":432,"ZJPF0105":"","ZJPF0103":"A","ZJPF0107":"","ZJPF0106":"upload/xm/示例图片_01_1371136099710.jpg"},{"ZJPF0101":434,"ZJPF0104":"2012","ZJPF0102":432,"ZJPF0105":"","ZJPF0103":"A","ZJPF0107":"","ZJPF0106":"upload/xm/示例图片_02_1371136109177.jpg"}]
		// {"XMQK01010":"","XMQK01007":"0000000","XMQK01127":"","XMQK01136":"武汉市","XMQK01133":"2.00","XMQK01137":"武昌区","XMQK01118":"2013-06-03","XMQK01134":"2.00","XMQK01012":"193","XMQK01119":"2013-06-12","XMQK01121":"2013-06-13","XMQK01006":"调查评价","XMQK01120":"验收组织部门","XMQK01124":"主审6","XMQK01002":"","XMQK01125":"成员6","XMQK01019":"200.00","XMQK01003":"老公最好","XMQK01001":"432","XMQK01004":"2013-06-05","XMQK01018":"100.00","XMQK01005":2012,"XMQK01017":"100.00","XMQK01122":"","XMQK01123":"","XMQK01011":"直接委托","XMQK01128":"2.00","XMQK01013":"乙级","XMQK01129":"2.00","XMQK01016":"灾害点","XMQK01015":"","XMQK01008":"111","XMQK01132":"无","XMQK01130":"2.00","XMQK01126":"","XMQK01014":"乙级","XMQK01009":"114","XMQK01135":"无","XMQK01131":"2.00"}
		// [{"CJDW0114":null,"CJDW0104":"A","CJDW0105":null,"CJDW0103":119,"CJDW0111":null,"CJDW0112":null,"CJDW0108":null,"CJDW0113":null,"CJDW0109":null,"CJDW0101":438,"CJDW0110":null,"CJDW0106":null,"CJDW0102":432,"CJDW0107":null},{"CJDW0114":null,"CJDW0104":"E","CJDW0105":null,"CJDW0103":113,"CJDW0111":null,"CJDW0112":null,"CJDW0108":null,"CJDW0113":null,"CJDW0109":null,"CJDW0101":437,"CJDW0110":null,"CJDW0106":null,"CJDW0102":432,"CJDW0107":null},{"CJDW0114":null,"CJDW0104":"A","CJDW0105":null,"CJDW0103":371,"CJDW0111":null,"CJDW0112":null,"CJDW0108":null,"CJDW0113":null,"CJDW0109":null,"CJDW0101":436,"CJDW0110":null,"CJDW0106":null,"CJDW0102":432,"CJDW0107":null},{"CJDW0114":null,"CJDW0104":"C","CJDW0105":null,"CJDW0103":114,"CJDW0111":null,"CJDW0112":null,"CJDW0108":null,"CJDW0113":null,"CJDW0109":null,"CJDW0101":435,"CJDW0110":null,"CJDW0106":null,"CJDW0102":432,"CJDW0107":null},{"CJDW0114":null,"CJDW0104":"D","CJDW0105":null,"CJDW0103":112,"CJDW0111":null,"CJDW0112":null,"CJDW0108":null,"CJDW0113":null,"CJDW0109":null,"CJDW0101":439,"CJDW0110":null,"CJDW0106":null,"CJDW0102":432,"CJDW0107":null}]

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		SystemManager sys=new SystemManagerImpl();
		String xmqkStr=request.getParameter("XMQKBASEINFO");//获取项目基本情况和竣工信息
		String cjdwStr=request.getParameter("CJDWLIST");//获取参建单位信息数组
		String zjpfStr=request.getParameter("ZJPFLIST");//获取资金批复信息数组
		String zhdStr = request.getParameter("ZHDLIST");//获取灾害点列表信息数组
		System.out.println(zjpfStr);
		System.out.println(xmqkStr);
		System.out.println(cjdwStr);
		System.out.println(zhdStr);
		/*zjpfStr ="[{\"ZJPF0101\":433,\"ZJPF0104\":\"2013\",\"ZJPF0102\":432,\"ZJPF0105\":\"\",\"ZJPF0103\":\"A\",\"ZJPF0107\":\"\",\"ZJPF0106\":\"upload/xm/示例图片_01_1371136099710.jpg\"},{\"ZJPF0101\":434,\"ZJPF0104\":\"2012\",\"ZJPF0102\":432,\"ZJPF0105\":\"\",\"ZJPF0103\":\"A\",\"ZJPF0107\":\"\",\"ZJPF0106\":\"upload/xm/示例图片_02_1371136109177.jpg\"}]";
		xmqkStr= "{\"XMQK01010\":\"\",\"XMQK01007\":\"0000000\",\"XMQK01127\":\"\",\"XMQK01136\":\"武汉市\",\"XMQK01133\":\"2.00\",\"XMQK01137\":\"武昌区\",\"XMQK01118\":\"2013-06-03\",\"XMQK01134\":\"2.00\",\"XMQK01012\":\"193\",\"XMQK01119\":\"2013-06-12\",\"XMQK01121\":\"2013-06-13\",\"XMQK01006\":\"调查评价\",\"XMQK01120\":\"验收组织部门\",\"XMQK01124\":\"主审6\",\"XMQK01002\":\"\",\"XMQK01125\":\"成员6\",\"XMQK01019\":\"200.00\",\"XMQK01003\":\"老公最好\",\"XMQK01001\":\"432\",\"XMQK01004\":\"2013-06-05\",\"XMQK01018\":\"100.00\",\"XMQK01005\":2012,\"XMQK01017\":\"100.00\",\"XMQK01122\":\"\",\"XMQK01123\":\"\",\"XMQK01011\":\"直接委托\",\"XMQK01128\":\"2.00\",\"XMQK01013\":\"乙级\",\"XMQK01129\":\"2.00\",\"XMQK01016\":\"灾害点\",\"XMQK01015\":\"\",\"XMQK01008\":\"111\",\"XMQK01132\":\"无\",\"XMQK01130\":\"2.00\",\"XMQK01126\":\"\",\"XMQK01014\":\"乙级\",\"XMQK01009\":\"114\",\"XMQK01135\":\"无\",\"XMQK01131\":\"2.00\"}";
		cjdwStr ="[{\"CJDW0114\":null,\"CJDW0104\":\"A\",\"CJDW0105\":null,\"CJDW0103\":119,\"CJDW0111\":null,\"CJDW0112\":null,\"CJDW0108\":null,\"CJDW0113\":null,\"CJDW0109\":null,\"CJDW0101\":438,\"CJDW0110\":null,\"CJDW0106\":null,\"CJDW0102\":432,\"CJDW0107\":null},{\"CJDW0114\":null,\"CJDW0104\":\"E\",\"CJDW0105\":null,\"CJDW0103\":113,\"CJDW0111\":null,\"CJDW0112\":null,\"CJDW0108\":null,\"CJDW0113\":null,\"CJDW0109\":null,\"CJDW0101\":437,\"CJDW0110\":null,\"CJDW0106\":null,\"CJDW0102\":432,\"CJDW0107\":null},{\"CJDW0114\":null,\"CJDW0104\":\"A\",\"CJDW0105\":null,\"CJDW0103\":371,\"CJDW0111\":null,\"CJDW0112\":null,\"CJDW0108\":null,\"CJDW0113\":null,\"CJDW0109\":null,\"CJDW0101\":436,\"CJDW0110\":null,\"CJDW0106\":null,\"CJDW0102\":432,\"CJDW0107\":null},{\"CJDW0114\":null,\"CJDW0104\":\"C\",\"CJDW0105\":null,\"CJDW0103\":114,\"CJDW0111\":null,\"CJDW0112\":null,\"CJDW0108\":null,\"CJDW0113\":null,\"CJDW0109\":null,\"CJDW0101\":435,\"CJDW0110\":null,\"CJDW0106\":null,\"CJDW0102\":432,\"CJDW0107\":null},{\"CJDW0114\":null,\"CJDW0104\":\"D\",\"CJDW0105\":null,\"CJDW0103\":112,\"CJDW0111\":null,\"CJDW0112\":null,\"CJDW0108\":null,\"CJDW0113\":null,\"CJDW0109\":null,\"CJDW0101\":439,\"CJDW0110\":null,\"CJDW0106\":null,\"CJDW0102\":432,\"CJDW0107\":null}]";
*/
		cjdwStr = cjdwStr.replaceAll("null", "\"\"");
		xmqkStr =xmqkStr.replaceAll("null", "\"\"");
		zjpfStr =zjpfStr.replaceAll("null", "\"\"");
		zhdStr  = zhdStr.replaceAll("null", "\"\"");
		Xmqk01New xmqk01 = (Xmqk01New)JSONObject.toBean(JSONObject.fromObject(xmqkStr),Xmqk01New.class);//转换成对象
		List<Zjpf01> zjpfList = JsonTools.getDTOList(zjpfStr, Zjpf01.class);//转换成数组
		List<Cjdw01> cjdwList =JsonTools.getDTOList(cjdwStr, Cjdw01.class);//转化成数组
		List<ZHD01> zhdList = JsonTools.getDTOList(zhdStr, ZHD01.class);
		boolean flag=sys.updateXmqk01ForOneToMany(xmqk01,zjpfList,cjdwList,zhdList);
		out.print(flag);
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
